package view
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import model.Image;
		
	public class PigButton extends Sprite
	{
		
		private var suspend:Image;
		private var getback:Image;
		public var num:NumRound;
		public var startButt:String = "assets/开始按钮.png";
		public var stopButt:String = "assets/暂停按钮.png";
		public var getbackButt:String = "assets/返回按钮.png";
		/**
		 * num.numText.text代表关卡,它是字符串；/n
		 * suspend暂停按钮 
		 * getback返回按钮
		 * 
		 */		
		public function PigButton()
		{
			super();
			suspend = new Image(stopButt);
			getback = new Image(getbackButt);
			num = new NumRound();
			addChild(num);
			addChild(suspend);
			addChild(getback);
			num.y = 14;
			suspend.y = getback.y = 18;
			num.x = 20;
			suspend.x = 440;
			getback.x = 520;
			
			suspend.addEventListener(Image.COMPLETE,onComplete);
			getback.addEventListener(Image.COMPLETE,onComplete);
		}
		private var tepNum:uint=0;
		protected function onComplete(event:Event):void
		{
			event.currentTarget.removeEventListener(Image.COMPLETE,onComplete);
			tepNum ++;
			if(tepNum == 2)
			{						
				suspend.addEventListener(MouseEvent.CLICK,onClickButton);
				getback.addEventListener(MouseEvent.CLICK,onClickButton);
				dispatchEvent(new Event(Image.COMPLETE));
				
			}
			
			
			
		}
		//点击的按钮名字
		public var buttonClidk:String;
		public static const CLICK_EVENT:String = "clickMe";
		private var exchange:Boolean = true;
		protected function onClickButton(event:MouseEvent):void
		{
			buttonClidk = event.currentTarget.url;
			
			if(buttonClidk == startButt || buttonClidk == stopButt)
			{
				if(exchange){
					event.currentTarget.url = startButt;
				}else{
					event.currentTarget.url = stopButt;
				}
				
				exchange = !exchange;
			}
			
			dispatchEvent(new Event(PigButton.CLICK_EVENT));			
		}
	}
}